/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sheep.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import org.jdesktop.swingx.JXMonthView;
import sheep.view.Component.ActionButton;
import sheep.view.Component.CalendarCellRenderer;
import sheep.view.Component.CalendarCellRenderer.Adapter;
import sheep.view.Component.CoolBar;
import sheep.view.Component.CoolButton;
import sheep.view.Component.RoundedPanel;
import org.jdesktop.swingx.JXCollapsiblePane;
import org.jdesktop.swingx.JXCollapsiblePane.Orientation;
import org.jdesktop.swingx.JXPanel;
import sheep.controller.Workspace;
import sheep.model.Calendrier;

import sheep.model.Note;
import sheep.model.Task;
import sheep.view.Component.CalendarCellRenderer.CalendarAdapter;
import sheep.view.Component.DayGridPanel;
import sheep.view.Component.DayGridPanelProject;
import sheep.view.Component.MonthGridPanel;
import sheep.view.Component.MonthGridPanelProject;
import sheep.view.Component.WeekGridPanel;
import sheep.view.Component.SheepScrollbarUI;
import sheep.view.Component.WeekGridPanelProject;
import sheep.view.transitions.TransitionTarget;
import sheep.view.transitions.ScreenTransition;
import sheep.view.utils.swingx.StackLayout;

/*
 * NewJPanel.java
 *
 * Created on 13 mars 2008, 16:54
 */

public class AgendaPanel extends javax.swing.JPanel {
  
  
  // duree des transitons
  private static final int TRANSITION_TIME_IN_MILLIS = 500;
  private JPanel dayNameTopDayPanel;
  private JPanel dayNameDayPanel;
  private JLabel yearDayLabel;
  private JLabel dayLabel;
  private JScrollPane agendaScrollDayPane;
  private JXPanel weekDayPanel;
  private JPanel dayPanel;
  private Component rightTopDayBox;
  private DayGridPanel gridDayPanel;
  private WeekGridPanel gridWeekPanel;
  private MonthGridPanel gridMonthPanel;

  private JPanel monthNameTopPanel;
  private JPanel monthNamePanel;
  private JLabel monthYearLabel;
  private JLabel monthLundiLabel;
  private JLabel monthMardiLabel;
  private JLabel monthMercrediLabel;
  private JLabel monthJeudiLabel;
  private JLabel monthVendrediLabel;
  private JLabel monthSamediLabel;
  private JLabel monthDimancheLabel;
  private JScrollPane agendaMonthScrollPane;
  private JXPanel monthPanel;
  private JPanel monthTimeLeftPanel;
  private JPanel monthLundiPanel;
  private JPanel monthMardiPanel;
  private JPanel monthMercrediPanel;
  private JPanel monthJeudiPanel;
  private JPanel monthVendrediPanel;
  private JPanel monthSamediPanel;
  private JPanel monthDimanchePanel;
  private Component monthRightTopBox;
    // Flag pour connaitre le panel affich"
  private enum ScreenType { DAY,WEEK,MONTH }
  // Valeur des ecrans courant et precedent
  private static ScreenType currentScreen;
  private static ScreenType oldScreen;   
  
  // Gestionnaire de transitions utilisee    
  private static ScreenTransition screenTransition; 
  
  
  
  JXPanel centerSatckPanel;
  
  /////////////////////////////////////////////////////////////////////////

  private class ContentTransitionTarget implements TransitionTarget {

  /////////////////////////////////////////////////////////////////////////

  @Override
  // Vide la zone principal
  public void resetCurrentScreen() {
     //centerPanel.removeAll();
    centerSatckPanel.removeAll();
     if (currentScreen== ScreenType.DAY || 
             currentScreen == ScreenType.WEEK)
       for ( Note testNote : workSpace.getNoteList())
         testNote.setNoteZone(null);
  }

  @Override
  // Ajoute le panel correspondant au flag au panel general
  public void setupNextScreen() {
     switch(currentScreen) {
        case DAY:
             //centerPanel.add(centerDayPanel, BorderLayout.CENTER);
             centerSatckPanel. add(centerDayPanel, StackLayout.TOP);
             centerSatckPanel.add(agendaNotePanel,StackLayout.TOP );
             centerSatckPanel.add(agendaCalendrierPanel,StackLayout.TOP ); 
             break;
        case WEEK:
             //centerPanel.add(centerWeekPanel, BorderLayout.CENTER);
             centerSatckPanel. add(centerWeekPanel, StackLayout.TOP);
             centerSatckPanel.add(agendaNotePanel,StackLayout.TOP );
             centerSatckPanel.add(agendaCalendrierPanel,StackLayout.TOP ); 
             break;   
        case MONTH:
             //centerPanel.add(centerMonthPanel, BorderLayout.CENTER);
             centerSatckPanel. add(centerMonthPanel, StackLayout.TOP);
             centerSatckPanel.add(agendaNotePanel,StackLayout.TOP );
             centerSatckPanel.add(agendaCalendrierPanel,StackLayout.TOP ); 
             break;      
        default:
              assert false;
              break;
     }    
  }
      
  @Override
  // Si on vient du slideshow, on le detruit
  public void transitionComplete() {}
 
  }
      
  /////////////////////////////////////////////////////////////////////////
  
    // Lance la trnsition vers le nouveau panel
  private static void startTransition(ScreenType newScreen) {
     if (newScreen != currentScreen) {
         oldScreen = currentScreen;
         currentScreen = newScreen;
         screenTransition.startTransition(TRANSITION_TIME_IN_MILLIS);
     }
  }
  
    // Affiche la panel principal
  public static  void showAgendaDay() {  
     startTransition(ScreenType.DAY);
     currentScreen = ScreenType.DAY;
  }
    
  // Affiche la panel de projet
  public static void showAgendaWeek() {       

     startTransition(ScreenType.WEEK);
     currentScreen = ScreenType.WEEK;
  }
    
  // Affiche la panel de projet
  public static void showAgendaMonth() {    
    startTransition(ScreenType.MONTH);
    currentScreen = ScreenType.MONTH;
    
  }
  
  
  private class ShowAgendaDayHandler implements ActionListener {
     public void actionPerformed(ActionEvent e) {showAgendaDay();}}
   
  private class ShowAgendaWeekHandler implements ActionListener {
     public void actionPerformed(ActionEvent e) {showAgendaWeek();}}  
  
   private class ShowAgendaMonthHandler implements ActionListener {
     public void actionPerformed(ActionEvent e) {showAgendaMonth();}}  
   

  
  
  /** Creates new form NewJPanel */
  public AgendaPanel(Workspace workSpace) {
    this.workSpace = workSpace;
    currentScreen = ScreenType.WEEK;  
    initComponents();
//    screenTransition = new ScreenTransition(centerPanel, 
//    new ContentTransitionTarget());
    
    screenTransition = new ScreenTransition(centerSatckPanel, 
    new ContentTransitionTarget());
    
    
  }
  

  private void initComponents() {

    setOpaque(false);
    BorderLayout borderLayout= new BorderLayout();
    //borderLayout.setHgap(10);
    borderLayout.setVgap(10);
    setLayout(borderLayout);

        //=================================
    //Partie au centre
    //=================================
    
    // Panel principal de l'agenda
    centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.setOpaque(false);
    
    calendarJList = new JList();
    
    agendaNotePanel = new AgendaNotePanel(workSpace);
    agendaCalendrierPanel = new AgendaCalendrierPanel(workSpace);
    agendaCalendrierPanel.setRepaintComponent(new Component[] {calendarJList, centerPanel});  
    
    centerDayPanel = createCenterDayButton();
    centerMonthPanel = createCenterMonthButton();
    centerWeekPanel = createCenterWeekButton();
    
 
            
    centerSatckPanel = new JXPanel(new StackLayout());
    centerSatckPanel. add(centerWeekPanel, StackLayout.TOP);
    agendaNotePanel.setVisible2(false);
    centerSatckPanel.add(agendaNotePanel,StackLayout.TOP );
    agendaCalendrierPanel.setVisible2(false);
    centerSatckPanel.add(agendaCalendrierPanel,StackLayout.TOP );  
    
    
    centerPanel.add(centerSatckPanel, BorderLayout.CENTER);
    RoundedPanel round =new RoundedPanel(centerPanel);
    add(round, java.awt.BorderLayout.CENTER);
    
    //=================================
    //Partie en haut
    //=================================
    
    headerPanel = new JXPanel();
    headerLeftPanel = new JPanel();
    todayButton = new ActionButton();
    headerCenterPanel = new JPanel();  
    headerRightPanel = new JPanel();
    jButton7 = new ActionButton();
    
    // Conteneur principal de l'en tete
    headerPanel.setOpaque(false);
    headerPanel.setLayout(new java.awt.BorderLayout()); 
    
    // Partie centrale de navigation
    headerCenterPanel.setOpaque(false);
    headerCenterPanel.setLayout(new BorderLayout());
    titleLabel = new JLabel("Agenda");
    titleLabel.setHorizontalAlignment(JLabel.CENTER);
    headerCenterPanel.add(titleLabel, java.awt.BorderLayout.NORTH);      
    headerPanel.add(headerCenterPanel, BorderLayout.NORTH);
    
    JPanel panel = new JPanel(new BorderLayout());
    panel.setOpaque(false);    
    panel.add(createMainToolBar(), BorderLayout.CENTER);

    // Partie de gauche, boutton aoujourd'hui
    headerLeftPanel.setOpaque(false);
    headerLeftPanel.setLayout(new java.awt.BorderLayout());
    todayButton.setText("Aujourd'hui");  
    todayButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        setDate(Calendar.getInstance());
        jXMonthView.setSelectedDate(workSpace.getCurrentDay().getTime());
        jXMonthView.setFirstDisplayedDate(workSpace.getCurrentDay().getTimeInMillis());
   
      }
    });
    headerLeftPanel.add(Box.createHorizontalStrut(25), java.awt.BorderLayout.WEST);
    headerLeftPanel.add(todayButton, java.awt.BorderLayout.CENTER);
    panel.add(headerLeftPanel, java.awt.BorderLayout.WEST);


    // Partie a droite
    headerRightPanel.setOpaque(false);
    headerRightPanel.setLayout(new java.awt.BorderLayout());
    jButton7.setText("EchÃ©ances <<");
    jButton7.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        rightPanel.setVisible(!rightPanel.isVisible());
        rightCollapsiblePane.setCollapsed(!rightCollapsiblePane.isCollapsed());        
        jButton7.setText("EchÃ©ances " + (rightCollapsiblePane.isCollapsed()? "<<" : ">>"));
      }
    });
    headerRightPanel.add(Box.createHorizontalStrut(25), java.awt.BorderLayout.EAST);
    headerRightPanel.add(jButton7, java.awt.BorderLayout.CENTER);
    //panel.add(headerRightPanel, java.awt.BorderLayout.EAST);

    headerPanel.add(panel, BorderLayout.CENTER);
    // Ajout de l'en tete
    add(new RoundedPanel(headerPanel), java.awt.BorderLayout.NORTH);
    
    //=================================
    //Partie a gauche
    //=================================
    
    // Constructeurs
    leftPanel = new JXPanel();
    jScrollPane2 = new JScrollPane();
    
    jPanel11 = new JPanel ( new BorderLayout());
    jXMonthView = new JXMonthView(new Date().getTime());
    jPanel11.add(jXMonthView, BorderLayout.CENTER);
    // Calendrier
    jXMonthView.setTraversable(true);
    jXMonthView.setDayForeground(1,Color.RED);
    jXMonthView.setDayForeground(7,Color.RED);
    jXMonthView.setDaysOfTheWeekForeground(Color.BLUE);
    jXMonthView.setSelectedBackground(Color.YELLOW);
    jXMonthView.setFirstDayOfWeek(java.util.Calendar.MONDAY);
    jXMonthView.setTodayBackground(Color.LIGHT_GRAY);
    jXMonthView.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(jXMonthView.getSelectedDate());
        workSpace.setCurrentDay(cal);
        repaint();
      }
    });
    jPanel11.setOpaque(false);
       
    // Conteneur Gauche general
    leftPanel.setBackground(new java.awt.Color(153, 153, 255));
    leftPanel.setOpaque(false);
    
    BorderLayout bdrLyt1 = new BorderLayout();
    bdrLyt1.setVgap(10);
    leftPanel.setLayout(bdrLyt1);  
    jScrollPane2.setBorder(null);
    jScrollPane2.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    
    // Ajout du model
     bcr = new CalendarCellRenderer(new CalendarAdapter());
     calendarJList.setCellRenderer(bcr);
     calendarJList.setListData(workSpace.getCalendarTab());
     calendarJList.addMouseListener(new MouseListener(){
      public void mouseClicked(MouseEvent e) {
       
     if (e.getClickCount()==2){
         agendaCalendrierPanel.setVisible(true, (Calendrier)calendarJList.getSelectedValue());
       }else if(jScrollPane2.getVerticalScrollBar().isVisible()){
      // Zone checkBox 
        if (e.getX()<30){
         if(((Calendrier)calendarJList.getSelectedValue()).getStatus() == Adapter.Status.NOT_SELECTED){ 
            ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.SELECTED);
            int index = calendarJList.locationToIndex(e.getPoint());
            Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);  
            calend.setIsDisplay(true);
            gridDayPanel.repaint();
            gridWeekPanel.repaint();
            gridMonthPanel.repaint();
         }else{
           ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.NOT_SELECTED);
           int index = calendarJList.locationToIndex(e.getPoint());
            Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);  
            calend.setIsDisplay(false);
            gridDayPanel.repaint();
            gridWeekPanel.repaint();
            gridMonthPanel.repaint();
         }
          // Zone couleur
         }else if (e.getX()>130 && e.getX()<180){         
             int index = calendarJList.locationToIndex(e.getPoint());
             Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);
             Color col = JColorChooser.showDialog(AgendaPanel.this, "Dialog Title", calend.getColor());
             if (col != null )
              calend.setColor(col); 
         }
         // Zone ampoule
         if (e.getX()>200){
             int index = calendarJList.locationToIndex(e.getPoint());
             Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);
             workSpace.setCurrentCalendrier(calend);
             calend.setIsDisplay(true);
             ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.SELECTED);
             Calendrier calend2;         
             for (int i = 0; i < calendarJList.getModel().getSize(); i++){
               calend2 = (Calendrier)calendarJList.getModel().getElementAt(i);
               if (calend2 == calend)
                    calend2.setCurrent(true);
               else
                    calend2.setCurrent(false);
             }
          }                
      }else{
       if (e.getX()<30){
         if(((Calendrier)calendarJList.getSelectedValue()).getStatus() == Adapter.Status.NOT_SELECTED){ 
            ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.SELECTED);
            int index = calendarJList.locationToIndex(e.getPoint());
            Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);  
            calend.setIsDisplay(true);
            gridDayPanel.repaint();
            gridWeekPanel.repaint();
            gridMonthPanel.repaint();
         }else{
           ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.NOT_SELECTED);
           int index = calendarJList.locationToIndex(e.getPoint());
            Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);  
            calend.setIsDisplay(false);
            gridDayPanel.repaint();
            gridWeekPanel.repaint();
            gridMonthPanel.repaint();
         }
          // Zone couleur
          }else if (e.getX()>150 && e.getX()<200){         
             int index = calendarJList.locationToIndex(e.getPoint());
             Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);
             Color col = JColorChooser.showDialog(AgendaPanel.this, "Dialog Title", calend.getColor());
             if (col != null )
              calend.setColor(col); 
           }
           // Zone ampoule
          else if (e.getX()>220){
             int index = calendarJList.locationToIndex(e.getPoint());
             Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index);
             workSpace.setCurrentCalendrier(calend);
             calend.setIsDisplay(true);
             ((Calendrier)calendarJList.getSelectedValue()).setStatus(Adapter.Status.SELECTED);
             Calendrier calend2;         
             for (int i = 0; i < calendarJList.getModel().getSize(); i++){
               calend2 = (Calendrier)calendarJList.getModel().getElementAt(i);
               if (calend2 == calend)
                    calend2.setCurrent(true);
               else
                    calend2.setCurrent(false);
             }
          }
      }
       calendarJList.repaint();
      }
      public void mousePressed(MouseEvent e) {}
      public void mouseReleased(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) { }     
     });     
    // Forcer toutes les case meme hauteur (hauteur de 1ere case)
     calendarJList.setPrototypeCellValue(workSpace.getCalendarList().getFirst());
    //Ajout de la liste a la scrollPane et de la scroll pane au left panel
    jScrollPane2.setViewportView(calendarJList);
    jScrollPane2.setOpaque(false);
    calendarLabel = new JLabel("CALENDRIER");
    calendarLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    calendarLabel.setOpaque(false);
    calendarLabel.setHorizontalAlignment(JLabel.CENTER);
    // Zone de list et de boutton
    BorderLayout bdrLyt = new BorderLayout();
    bdrLyt.setVgap(10);
    JPanel temppanel =new JPanel(bdrLyt);
    temppanel.setOpaque(false);
    temppanel.add(jScrollPane2, java.awt.BorderLayout.CENTER);
    // Zone de bouttons
    GridLayout grdLyt = new GridLayout (1,4);
    JPanel temppanel2 =new JPanel(grdLyt);
    temppanel2.setOpaque(false);
    // Boutton ajouter calendrier
    JButton button1 =new ActionButton("+",new Dimension (25,25));
    button1.setText("+");
    button1.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
       agendaCalendrierPanel.setVisible(true);
      }
    });
    temppanel2.add(button1);
    // Boutton supprimer calendrier
    JButton button2 =new ActionButton("-",new Dimension (25,25));
    button2.setText("-");
    button2.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        int index = calendarJList.getSelectedIndex();
        if (index>=0){
          Calendrier cal = workSpace.getCalendarList().get(calendarJList.getSelectedIndex());
          for (Note n: cal.getNoteList()){
            workSpace.getNoteList().remove(n);
            gridDayPanel.noteList.remove(n);
            gridDayPanel.sortedList.remove(n);
            gridWeekPanel.noteList.remove(n);
            gridWeekPanel.sortedList.remove(n); 
            gridMonthPanel.noteList.remove(n);
            gridMonthPanel.sortedList.remove(n); 
          }        
           workSpace.getCalendarList().remove(calendarJList.getSelectedIndex());
           calendarJList.setListData(workSpace.getCalendarTab());
           calendarJList.repaint();
           gridDayPanel.repaint();
           gridWeekPanel.repaint();
       
           gridMonthPanel.repaint();
           centerPanel.repaint();
           if(index >0){
             Calendrier calend = (Calendrier)calendarJList.getModel().getElementAt(index-1);
             workSpace.setCurrentCalendrier(calend);
             calend.setIsDisplay(true);
             calend.setStatus(Adapter.Status.SELECTED);
             Calendrier calend2;         
             for (int i = 0; i < calendarJList.getModel().getSize(); i++){
               calend2 = (Calendrier)calendarJList.getModel().getElementAt(i);
               if (calend2 == calend)
                    calend2.setCurrent(true);
               else
                    calend2.setCurrent(false);
             }
           }else if(index ==0){
             workSpace.setCurrentCalendrier(null);
            workSpace.setNoteList(new LinkedList<Note>());
            gridDayPanel.noteList = new LinkedList<Note>();
            gridDayPanel.sortedList= new LinkedList<Note>();
            gridWeekPanel.noteList= new LinkedList<Note>();
            gridWeekPanel.sortedList= new LinkedList<Note>(); 
            gridMonthPanel.noteList= new LinkedList<Note>();
            gridMonthPanel.sortedList= new LinkedList<Note>();              
             
             
           }
        }
      }
    });    
    
    temppanel2.add(button2);
    // Boutton afficher tous
    JButton button3 =new ActionButton("V",new Dimension (25,25));
    button3.setText("V");
    button3.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        for (Calendrier cal : workSpace.getCalendarList()){
          cal.setIsDisplay(true);
          cal.setStatus(Adapter.Status.SELECTED);
        }
        calendarJList.setListData(workSpace.getCalendarTab());
        calendarJList.repaint();
        centerPanel.repaint();
      }
    });     
    
    
    temppanel2.add(button3);
    // Boutton cacher tous
    JButton button4 =new ActionButton("X",new Dimension (25,25));
    button4.setText("X");
    button4.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        int i =0;
        for (Calendrier cal : workSpace.getCalendarList()){
          if (calendarJList.getSelectedIndex()!=i){
            cal.setIsDisplay(false);
            cal.setStatus(Adapter.Status.NOT_SELECTED);
            centerPanel.repaint();
          }
          i++;
        }
        calendarJList.setListData(workSpace.getCalendarTab());
        calendarJList.repaint();
        
      }
    }); 
    temppanel2.add(button4);
    
    temppanel.add(temppanel2, java.awt.BorderLayout.SOUTH);   
    leftPanel.add(calendarLabel, java.awt.BorderLayout.NORTH);
    leftPanel.add(new RoundedPanel(temppanel), java.awt.BorderLayout.CENTER);
    leftPanel.add(new RoundedPanel(jPanel11), java.awt.BorderLayout.SOUTH);
    jScrollPane3 = new JScrollPane();
    jScrollPane3.setOpaque(false);
    jScrollPane3.setViewportView(leftPanel);
    jScrollPane3.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    JPanel pan1 = new JPanel (new BorderLayout());
    pan1.setOpaque(false);
    pan1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    pan1.add(new RoundedPanel(leftPanel),BorderLayout.CENTER);
    add(pan1, java.awt.BorderLayout.WEST);
   
    //=================================
    //Partie a Droite
    //=================================
    
    rightPanel = new JXPanel();
    jScrollPane1 = new JScrollPane();
    echeancesJList = new JList();
        
    rightPanel.setOpaque(false);    
    rightPanel.setLayout(new java.awt.BorderLayout());  
    jScrollPane1.setBorder(null);
        
    //Ajout de la liste a la scrollPane et de la scroll pane au left panel
    jScrollPane1.setViewportView(echeancesJList);
    jScrollPane1.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    
    echeancesLabel = new JLabel("ECHEANCES");
    echeancesLabel.setOpaque(false);
    echeancesLabel.setHorizontalAlignment(JLabel.CENTER);
    
    rightPanel.add(echeancesLabel, java.awt.BorderLayout.NORTH);
    rightPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
    
    rightCollapsiblePane = new JXCollapsiblePane();  
    rightCollapsiblePane.setContentPane(new RoundedPanel(rightPanel));
    rightCollapsiblePane.setBorder(new EmptyBorder(0,0,0,0));
    rightCollapsiblePane.setLayout(new BorderLayout());
    rightCollapsiblePane.setOrientation(Orientation.HORIZONTAL);
    rightCollapsiblePane.setCollapsed(true);  
    rightPanel.setVisible(false);
    
    JPanel pan2 = new JPanel (new BorderLayout());
    pan2.setOpaque(false);
    pan2.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    pan2.add(rightCollapsiblePane,BorderLayout.CENTER);
    
    //add(pan2, java.awt.BorderLayout.EAST);
       


    
    //=================================
    // Partie en bas
    //=================================
    
    // En bas
    bottomPanel = new JXPanel();
    bottomLeftPanel = new JPanel();
    jButton3 = new JButton();
    jButton4 = new JButton();
    jButton2 = new JButton();
    bottomCenterPanel = new JPanel();
    bottomRightPanel = new JPanel();
    jButton5 = new JButton();
    bottomPanel.setOpaque(false);
    bottomPanel.setLayout(new BorderLayout());
    bottomLeftPanel.setOpaque(false);
    bottomLeftPanel.setLayout(new BoxLayout(bottomLeftPanel, BoxLayout.LINE_AXIS));

    jButton3.setText("jButton2");
    jButton3.addActionListener(new ActionListener(){

      public void actionPerformed(ActionEvent e) {
        JFrame frame = new JFrame();// panel de fond general, dÃ©gradÃ©
        ContentPanel contentPanel = new ContentPanel();
        contentPanel.setLayout(new BorderLayout());   
        
        AgendaPanel agendaWeekPanel = new AgendaPanel(workSpace);
        agendaWeekPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 
        contentPanel.add(agendaWeekPanel, BorderLayout.CENTER);
        frame.setContentPane(contentPanel);
        frame.setVisible(true);
        frame.pack();
        frame.setSize(1020, 620);
      }    
    });  
    bottomLeftPanel.add(jButton3);
    
    jButton4.setText("jButton2");
    bottomLeftPanel.add(jButton4);
    jButton2.setText("jButton2");
    bottomLeftPanel.add(jButton2);

    bottomPanel.add(bottomLeftPanel, BorderLayout.WEST);
    bottomCenterPanel.setOpaque(false);
    bottomCenterPanel.setLayout(new BorderLayout());
    bottomPanel.add(bottomCenterPanel,BorderLayout.CENTER);
    
    bottomRightPanel.setOpaque(false);
    bottomRightPanel.setLayout(new BoxLayout(bottomRightPanel, BoxLayout.LINE_AXIS));
    jButton5.setText("jButton5");
    bottomRightPanel.add(jButton5);

    bottomPanel.add(bottomRightPanel, java.awt.BorderLayout.EAST);

    //add(new RoundedPanel(bottomPanel), java.awt.BorderLayout.SOUTH);

  }

 /////////////////////////////////////////////////////////////////////////
     
 public void setDate( Calendar cal){
   workSpace.setCurrentDay(cal);
   repaint();
 }
  
 public Calendar getDate(){
   return workSpace.getCurrentDay();
 }
 
 @Override
 protected void paintComponent(Graphics g) {
  if (!init){
    agendaScrollPane.getVerticalScrollBar().setValue(300);
    init = true;
  }
  
  //calendarJList.setListData(workSpace.getCalendarTab());
   
   if (calendarJList.getModel().getSize() != workSpace.getCalendarList().size()){
     calendarJList.setListData(workSpace.getCalendarTab());
     calendarJList.repaint();
   }
  
 if (currentScreen == ScreenType.WEEK){

  Calendar temp = Calendar.getInstance();
  temp.setTime(workSpace.getCurrentDay().getTime());
    
  //Calendar temp = workSpace.getCurrentDay();
  int dec = ((temp.get(Calendar.DAY_OF_WEEK)+5)%7);
  temp.add(Calendar.DAY_OF_YEAR, - dec);

  LundiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                     dayMonthName[temp.get(Calendar.MONTH)]);       
  temp.add(Calendar.DAY_OF_YEAR, 1);
  mardiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                     dayMonthName[temp.get(Calendar.MONTH)]);    
  temp.add(Calendar.DAY_OF_YEAR, 1);
  mercrediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
  temp.add(Calendar.DAY_OF_YEAR, 1);
  jeudiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                     dayMonthName[temp.get(Calendar.MONTH)]);   
  temp.add(Calendar.DAY_OF_YEAR, 1);
  vendrediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
  temp.add(Calendar.DAY_OF_YEAR, 1);
  samediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                      dayMonthName[temp.get(Calendar.MONTH)]);  
  temp.add(Calendar.DAY_OF_YEAR, 1);
  dimancheLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
  
  temp.add(Calendar.DAY_OF_YEAR, -6);
  //temp.add(Calendar.DAY_OF_YEAR, dec);
 }else  if ( currentScreen == ScreenType.DAY){
  dayLabel.setText(dayTabName[(workSpace.getCurrentDay().get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  
                      workSpace.getCurrentDay().get(Calendar.DAY_OF_MONTH) + " " +
                      dayMonthName[workSpace.getCurrentDay().get(Calendar.MONTH)]);
 }
  
  
  if (!rightCollapsiblePane.isCollapsed()  && !TransitionManager.isToolBarDisplay()){
    dayNameTopPanel.remove(rightTopBox);
    rightTopBox = Box.createHorizontalStrut(15);  
    dayNameTopPanel.add(rightTopBox, java.awt.BorderLayout.EAST);
  }else{
    dayNameTopPanel.remove(rightTopBox);
    rightTopBox = Box.createHorizontalStrut(20);  
    dayNameTopPanel.add(rightTopBox, java.awt.BorderLayout.EAST);
  }
  
  
  
  if (currentScreen == ScreenType.MONTH){
    yearLabel.setText(dayMonthName[workSpace.getCurrentDay().get(Calendar.MONTH)] + 
            " " + workSpace.getCurrentDay().get(Calendar.YEAR));
    monthYearLabel.setText(dayMonthName[workSpace.getCurrentDay().get(Calendar.MONTH)] + 
            " " + workSpace.getCurrentDay().get(Calendar.YEAR));
  }
  else{
    yearLabel.setText("" + workSpace.getCurrentDay().get(Calendar.YEAR));
    monthYearLabel.setText("" + workSpace.getCurrentDay().get(Calendar.YEAR));
  }
  


       
  super.paintComponent(g);
 }
 
 
  private JPanel createCenterMonthButton(){
    // Panel principal de l'agenda
    centerMonthPanel = new JPanel();   
    // Jour et date
    monthNameTopPanel = new JPanel();
    monthNamePanel = new JPanel();
    monthYearLabel = new JLabel();
    monthLundiLabel = new JLabel();
    monthMardiLabel = new JLabel();
    monthMercrediLabel = new JLabel();
    monthJeudiLabel = new JLabel();
    monthVendrediLabel = new JLabel();
    monthSamediLabel = new JLabel();
    monthDimancheLabel = new JLabel();
    
    // Conteneur de l'agenda
    agendaMonthScrollPane = new JScrollPane();
    agendaMonthScrollPane.getVerticalScrollBar().setUnitIncrement(40);
    monthPanel = new JXPanel();
    
    // Panel de l'agenada
    monthTimeLeftPanel = new JPanel();
    monthLundiPanel = new JPanel();
    monthMardiPanel = new JPanel();
    monthMercrediPanel = new JPanel();
    monthJeudiPanel = new JPanel();
    monthVendrediPanel = new JPanel();
    monthSamediPanel = new JPanel();
    monthDimanchePanel = new JPanel();
    
    centerMonthPanel.setLayout(new BorderLayout());
    //centerMonthPanel.setOpaque(false);
    
    monthNameTopPanel.setBackground(new java.awt.Color(255, 255, 255));
    monthNameTopPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(204, 204, 204)));

    monthNameTopPanel.setLayout(new BorderLayout());

    monthRightTopBox = Box.createHorizontalStrut(20);  
    monthNameTopPanel.add(monthRightTopBox, java.awt.BorderLayout.EAST);

    monthNamePanel.setOpaque(false);
    monthNamePanel.setLayout(new java.awt.GridLayout(1, 8));

    monthYearLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 12));
    monthYearLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthYearLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthYearLabel.setText("" + workSpace.getCurrentDay().get(Calendar.YEAR));
    monthYearLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthNamePanel.add(monthYearLabel);

    
    monthLundiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthLundiLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthLundiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthLundiLabel.setText(dayTabName[0]);  
    monthNamePanel.add(monthLundiLabel);

  
    monthMardiLabel.setBackground(new java.awt.Color(255, 255, 224));
    monthMardiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthMardiLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthMardiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthMardiLabel.setText("mar XX Xxx.");
    monthMardiLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthMardiLabel.setText(dayTabName[1]);  
    monthNamePanel.add(monthMardiLabel);


    
    monthMercrediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthMercrediLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthMercrediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthMercrediLabel.setText(dayTabName[2]);  
    monthNamePanel.add(monthMercrediLabel);


    
    monthJeudiLabel.setBackground(new java.awt.Color(255, 255, 224));
    monthJeudiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthJeudiLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthJeudiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthJeudiLabel.setText(dayTabName[3]); 
    monthJeudiLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthJeudiLabel.setOpaque(true);
    monthNamePanel.add(monthJeudiLabel);


    
    monthVendrediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthVendrediLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthVendrediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthNamePanel.add(monthVendrediLabel);
    monthVendrediLabel.setText(dayTabName[4]); 

    
    monthSamediLabel.setBackground(new java.awt.Color(255, 255, 224));
    monthSamediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthSamediLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthSamediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthSamediLabel.setText(dayTabName[5]);  
    monthSamediLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthSamediLabel.setOpaque(true);
    monthNamePanel.add(monthSamediLabel);

 
    
    monthDimancheLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    monthDimancheLabel.setForeground(new java.awt.Color(102, 102, 102));
    monthDimancheLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    monthDimancheLabel.setText(dayTabName[6]);  
    monthDimancheLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1, new java.awt.Color(204, 204, 204)));
    monthNamePanel.add(monthDimancheLabel);

    
    monthNameTopPanel.add(monthNamePanel, java.awt.BorderLayout.CENTER);

    centerMonthPanel.add(monthNameTopPanel, java.awt.BorderLayout.NORTH);

    agendaMonthScrollPane.setBorder(new EmptyBorder(0,0,0,0));
    agendaMonthScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    agendaMonthScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    agendaMonthScrollPane.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    
    JPanel stackPanel = new JPanel(new StackLayout());
    gridMonthPanel =new MonthGridPanel(6,8, agendaNotePanel, workSpace);
    
    stackPanel.setBorder(new EmptyBorder(0,5,0,0));
    stackPanel.add(monthPanel, StackLayout.TOP); 
    stackPanel.add(gridMonthPanel,StackLayout.TOP );

    monthPanel.setLayout(new java.awt.GridLayout(1,8));
    
    monthTimeLeftPanel.setBackground(new java.awt.Color(255, 255, 255));
    monthTimeLeftPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthPanel.add(monthTimeLeftPanel);
    
    monthLundiPanel.setBackground(new java.awt.Color(255, 255, 255));
    monthPanel.add(monthLundiPanel);
    
    monthMardiPanel.setBackground(new java.awt.Color(255, 255, 224));
    monthMardiPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthPanel.add(monthMardiPanel);

    monthMercrediPanel.setBackground(new java.awt.Color(255, 255, 255));
    monthPanel.add(monthMercrediPanel);

    monthJeudiPanel.setBackground(new java.awt.Color(255, 255, 224));
    monthJeudiPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthPanel.add(monthJeudiPanel);

    monthVendrediPanel.setBackground(new java.awt.Color(255, 255, 255));
    monthPanel.add(monthVendrediPanel);

    monthSamediPanel.setBackground(new java.awt.Color(255, 255, 224));
    monthSamediPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    monthPanel.add(monthSamediPanel);

    monthDimanchePanel.setBackground(new java.awt.Color(255, 255, 255));
    monthDimanchePanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1, new java.awt.Color(204, 204, 204)));
    monthPanel.add(monthDimanchePanel);
    
    monthPanel.setPreferredSize(new Dimension (monthPanel.getPreferredSize().width, 640));
      
    agendaMonthScrollPane.setViewportView(stackPanel);
    agendaMonthScrollPane.getVerticalScrollBar().setValue(agendaMonthScrollPane.getVerticalScrollBar().getMaximum()/2);
    
    
    
    centerMonthPanel.add(agendaMonthScrollPane, java.awt.BorderLayout.CENTER);   
    
    
    MonthGridPanelProject weekGridPanelProject =new MonthGridPanelProject (workSpace);
    
    JScrollPane scroll = new JScrollPane();
    scroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scroll.getVerticalScrollBar().setUI(new SheepScrollbarUI());    
    scroll.setOpaque(false);
    weekGridPanelProject.setPreferredSize(new Dimension(500,300));
    scroll.setViewportView(weekGridPanelProject);
    scroll.setPreferredSize(new Dimension(500,80));
    scroll.getViewport().setOpaque(false);
    //GradientPaint   p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, getHeight() - 1, new Color(100, 100, 100));
    centerMonthPanel.setBackground(new Color(150,150,255));
    
    
    
    centerMonthPanel.add(new RoundedPanel(scroll), java.awt.BorderLayout.SOUTH);  
    
    
    
    return centerMonthPanel;
 } 
 
  
  
 private JPanel createCenterWeekButton(){
    // Panel principal de l'agenda
    centerWeekPanel = new JPanel();   
    // Jour et date
    dayNameTopPanel = new JPanel();
    dayNamePanel = new JPanel();
    yearLabel = new JLabel();
    LundiLabel = new JLabel();
    mardiLabel = new JLabel();
    mercrediLabel = new JLabel();
    jeudiLabel = new JLabel();
    vendrediLabel = new JLabel();
    samediLabel = new JLabel();
    dimancheLabel = new JLabel();
    
    // Conteneur de l'agenda
    agendaScrollPane = new JScrollPane();
    agendaScrollPane.getVerticalScrollBar().setUnitIncrement(40);
    weekPanel = new JXPanel();
    
    // Panel de l'agenada
    timeLeftPanel = new JPanel();
    lundiPanel = new JPanel();
    mardiPanel = new JPanel();
    mercrediPanel = new JPanel();
    jeudiPanel = new JPanel();
    vendrediPanel = new JPanel();
    samediPanel = new JPanel();
    dimanchePanel = new JPanel();
    
    centerWeekPanel.setLayout(new BorderLayout());
    //centerWeekPanel.setOpaque(false);
    
    dayNameTopPanel.setBackground(new java.awt.Color(255, 255, 255));
    dayNameTopPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(204, 204, 204)));

    dayNameTopPanel.setLayout(new BorderLayout());

    rightTopBox = Box.createHorizontalStrut(20);  
    dayNameTopPanel.add(rightTopBox, java.awt.BorderLayout.EAST);

    dayNamePanel.setOpaque(false);
    dayNamePanel.setLayout(new java.awt.GridLayout(1, 8));

    yearLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 12));
    yearLabel.setForeground(new java.awt.Color(102, 102, 102));
    yearLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    yearLabel.setText("" + workSpace.getCurrentDay().get(Calendar.YEAR));
    yearLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    dayNamePanel.add(yearLabel);

    Calendar temp = Calendar.getInstance(getDate().getTimeZone());
    temp.add(Calendar.DAY_OF_YEAR, - ((temp.get(Calendar.DAY_OF_WEEK)+5)%7));
    
    LundiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    LundiLabel.setForeground(new java.awt.Color(102, 102, 102));
    LundiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    LundiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
    dayNamePanel.add(LundiLabel);

    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    mardiLabel.setBackground(new java.awt.Color(255, 255, 224));
    mardiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    mardiLabel.setForeground(new java.awt.Color(102, 102, 102));
    mardiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    mardiLabel.setText("mar XX Xxx.");
    mardiLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    mardiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
    dayNamePanel.add(mardiLabel);

    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    mercrediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    mercrediLabel.setForeground(new java.awt.Color(102, 102, 102));
    mercrediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    mercrediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
    dayNamePanel.add(mercrediLabel);

    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    jeudiLabel.setBackground(new java.awt.Color(255, 255, 224));
    jeudiLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    jeudiLabel.setForeground(new java.awt.Color(102, 102, 102));
    jeudiLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jeudiLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]); 
    jeudiLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    jeudiLabel.setOpaque(true);
    dayNamePanel.add(jeudiLabel);

    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    vendrediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    vendrediLabel.setForeground(new java.awt.Color(102, 102, 102));
    vendrediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    dayNamePanel.add(vendrediLabel);
    vendrediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]); 
    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    samediLabel.setBackground(new java.awt.Color(255, 255, 224));
    samediLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    samediLabel.setForeground(new java.awt.Color(102, 102, 102));
    samediLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    samediLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
    samediLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    samediLabel.setOpaque(true);
    dayNamePanel.add(samediLabel);

    temp.add(Calendar.DAY_OF_YEAR, 1);
    
    dimancheLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    dimancheLabel.setForeground(new java.awt.Color(102, 102, 102));
    dimancheLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    dimancheLabel.setText(dayTabName[(temp.get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  temp.get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[temp.get(Calendar.MONTH)]);  
    dimancheLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1, new java.awt.Color(204, 204, 204)));
    dayNamePanel.add(dimancheLabel);

    
    dayNameTopPanel.add(dayNamePanel, java.awt.BorderLayout.CENTER);

    centerWeekPanel.add(dayNameTopPanel, java.awt.BorderLayout.NORTH);

    agendaScrollPane.setBorder(new EmptyBorder(0,0,0,0));
   
    agendaScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    agendaScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    agendaScrollPane.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    
    JPanel stackPanel = new JPanel(new StackLayout());

    gridWeekPanel =new WeekGridPanel(48,8, agendaNotePanel, workSpace);
    
    stackPanel.setBorder(new EmptyBorder(0,5,0,0));
    stackPanel.add(weekPanel, StackLayout.TOP); 
    stackPanel.add(gridWeekPanel,StackLayout.TOP );

    weekPanel.setLayout(new java.awt.GridLayout(1,8));
    
    timeLeftPanel.setBackground(new java.awt.Color(255, 255, 255));
    timeLeftPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    weekPanel.add(timeLeftPanel);
    
    lundiPanel.setBackground(new java.awt.Color(255, 255, 255));
    weekPanel.add(lundiPanel);
    
    mardiPanel.setBackground(new java.awt.Color(255, 255, 224));
    mardiPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    weekPanel.add(mardiPanel);

    mercrediPanel.setBackground(new java.awt.Color(255, 255, 255));
    weekPanel.add(mercrediPanel);

    jeudiPanel.setBackground(new java.awt.Color(255, 255, 224));
    jeudiPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    weekPanel.add(jeudiPanel);

    vendrediPanel.setBackground(new java.awt.Color(255, 255, 255));
    weekPanel.add(vendrediPanel);

    samediPanel.setBackground(new java.awt.Color(255, 255, 224));
    samediPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    weekPanel.add(samediPanel);

    dimanchePanel.setBackground(new java.awt.Color(255, 255, 255));
    dimanchePanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 0, 1, new java.awt.Color(204, 204, 204)));
    weekPanel.add(dimanchePanel);
    
    weekPanel.setPreferredSize(new Dimension (weekPanel.getPreferredSize().width, 1000));
      
    agendaScrollPane.setViewportView(stackPanel);
    agendaScrollPane.getVerticalScrollBar().setValue(agendaScrollPane.getVerticalScrollBar().getMaximum()/2);
      
    centerWeekPanel.add(agendaScrollPane, java.awt.BorderLayout.CENTER);   
    
    WeekGridPanelProject weekGridPanelProject =new WeekGridPanelProject (workSpace);
    
    JScrollPane scroll = new JScrollPane();
    scroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scroll.getVerticalScrollBar().setUI(new SheepScrollbarUI());    
    scroll.setOpaque(false);
    weekGridPanelProject.setPreferredSize(new Dimension(500,160));
    scroll.setViewportView(weekGridPanelProject);
    scroll.setPreferredSize(new Dimension(500,80));
    scroll.getViewport().setOpaque(false);
    //GradientPaint   p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, getHeight() - 1, new Color(100, 100, 100));
    centerWeekPanel.setBackground(new Color(150,150,255));
    
    
    centerWeekPanel.add(new RoundedPanel(scroll), java.awt.BorderLayout.SOUTH);  
    return centerWeekPanel;
 } 
 
 
 private JPanel createCenterDayButton(){
    // Panel principal de l'agenda
    centerDayPanel = new JPanel();  
    // Jour et date
    dayNameTopDayPanel = new JPanel();
    dayNameDayPanel = new JPanel();
    yearDayLabel = new JLabel();
    dayLabel = new JLabel();

    // Conteneur de l'agenda
    agendaScrollDayPane = new javax.swing.JScrollPane();
    agendaScrollDayPane.getVerticalScrollBar().setUnitIncrement(40);
    weekDayPanel = new JXPanel();
    
    // Panel de l'agenada
    dayPanel = new JPanel();
      
    centerDayPanel.setLayout(new java.awt.BorderLayout());
    //centerDayPanel.setOpaque(false);
    
    dayNameTopDayPanel.setLayout(new BorderLayout());
    rightTopDayBox = Box.createHorizontalStrut(17);   
    dayNameTopDayPanel.add(rightTopDayBox, java.awt.BorderLayout.EAST);

    dayNameDayPanel.setOpaque(false);
    dayNameDayPanel.setLayout(new BorderLayout());
    
    yearDayLabel.setFont(new java.awt.Font("Comic Sans MS", 1, 12));
    yearDayLabel.setForeground(new java.awt.Color(255, 255, 255));
    yearDayLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    yearDayLabel.setText("" + workSpace.getCurrentDay().get(Calendar.YEAR));
    yearDayLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    yearDayLabel.setPreferredSize(new Dimension(100, 15));
    yearDayLabel.setMaximumSize(new Dimension(100, 15));
    yearDayLabel.setOpaque(false);
    dayNameDayPanel.add(yearDayLabel, BorderLayout.WEST);


    dayLabel.setBackground(new java.awt.Color(255, 255, 224));
    dayLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12));
    dayLabel.setForeground(new java.awt.Color(102, 102, 102));
    dayLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    dayLabel.setText(dayTabName[(workSpace.getCurrentDay().get(Calendar.DAY_OF_WEEK)+5)%7]+" " +  workSpace.getCurrentDay().get(Calendar.DAY_OF_MONTH) + " " +
                        dayMonthName[workSpace.getCurrentDay().get(Calendar.MONTH)]); 
    dayLabel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    dayLabel.setOpaque(true); 
    dayNameDayPanel.add(dayLabel, BorderLayout.CENTER);

    dayNameTopDayPanel.add(dayNameDayPanel, java.awt.BorderLayout.CENTER);

    centerDayPanel.add(dayNameTopDayPanel, java.awt.BorderLayout.NORTH);

    agendaScrollDayPane.setBorder(new EmptyBorder(0,0,0,0));
    agendaScrollDayPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    agendaScrollDayPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    agendaScrollDayPane.getVerticalScrollBar().setUI(new SheepScrollbarUI());
    
    JPanel stackPanel = new JPanel(new StackLayout());

    gridDayPanel =new DayGridPanel(48,2, agendaNotePanel, workSpace);
    
    stackPanel.setBorder(new EmptyBorder(0,5,0,0));
    stackPanel.add(weekDayPanel, StackLayout.TOP);  
    stackPanel.add(gridDayPanel,StackLayout.TOP );

    
    weekDayPanel.setLayout(new BorderLayout());  
    Component b =Box.createHorizontalStrut(100);
    weekDayPanel.setBackground(Color.WHITE);  
    weekDayPanel.add(b, BorderLayout.WEST);
    dayPanel.setBackground(new java.awt.Color(255, 255, 224));
    dayPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 1, new java.awt.Color(204, 204, 204)));
    weekDayPanel.add(dayPanel, BorderLayout.CENTER);  
    weekDayPanel.setPreferredSize(new Dimension (weekDayPanel.getPreferredSize().width, 1000));
 
 
    agendaScrollDayPane.setViewportView(stackPanel);
    
    
    
    agendaScrollDayPane.getVerticalScrollBar().setValue(agendaScrollDayPane.getVerticalScrollBar().getMaximum()/2);
      
    
    centerDayPanel.add(agendaScrollDayPane, java.awt.BorderLayout.CENTER);

    DayGridPanelProject weekGridPanelProject =new DayGridPanelProject (workSpace);
    
    JScrollPane scroll = new JScrollPane();
    scroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scroll.getVerticalScrollBar().setUI(new SheepScrollbarUI());    
    scroll.setOpaque(false);
    weekGridPanelProject.setPreferredSize(new Dimension(500,160));
    scroll.setViewportView(weekGridPanelProject);
    scroll.setPreferredSize(new Dimension(500,80));
    scroll.getViewport().setOpaque(false);
    //GradientPaint   p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, getHeight() - 1, new Color(100, 100, 100));
    centerDayPanel.setBackground(new Color(150,150,255));
    
    
    centerDayPanel.add(new RoundedPanel(scroll), java.awt.BorderLayout.SOUTH);  
    
    
    
   return centerDayPanel;
 }  
 
 
  
 
 
 
 
 
  private JComponent createMainToolBar() {
    JToolBar mainTempToolBar = new CoolBar(false);
    mainTempToolBar.setBorder(new EmptyBorder(0,0,0,0));
    mainTempToolBar.setFloatable(false);
    mainTempToolBar.setOrientation(JToolBar.VERTICAL);
    mainTempToolBar.setOpaque(false);
    mainTempToolBar.setVisible(true);        
    FlowLayout flowLayout= new FlowLayout();
    flowLayout.setVgap(0);
    mainTempToolBar.setLayout(flowLayout);
    JComponent retComp;       
    retComp = mainTempToolBar;
     
    JButton previousButton = createToolbarButton("", "previous", 4);
    previousButton.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
        Calendar cal = getDate();
        if ( currentScreen == ScreenType.DAY)
          cal.add(Calendar.DAY_OF_YEAR, -1);
        else if (currentScreen == ScreenType.WEEK)
          cal.add(Calendar.DAY_OF_YEAR, -7);
        else if (currentScreen == ScreenType.MONTH)
          cal.add(Calendar.DAY_OF_YEAR, -dayMonthNumb[cal.get(Calendar.MONTH)]);
        setDate(cal);
        jXMonthView.setSelectedDate(cal.getTime());
        jXMonthView.setFirstDisplayedDate(workSpace.getCurrentDay().getTimeInMillis());
      }
    }); 
        
    JButton dayButton = createToolbarButton("Jour", "", 2);
    dayButton.addActionListener(new ShowAgendaDayHandler());  
    
    JButton weekButton = createToolbarButton("Semaine", "", 2);
    weekButton.addActionListener(new ShowAgendaWeekHandler());
    
    JButton monthButton = createToolbarButton("Mois", "", 2);
    monthButton.addActionListener(new ShowAgendaMonthHandler());
    
    JButton nextButton = createToolbarButton("", "next", 6);        
    nextButton.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
        Calendar cal = getDate();
        if ( currentScreen == ScreenType.DAY)
          cal.add(Calendar.DAY_OF_YEAR, 1);
        else if (currentScreen == ScreenType.WEEK)
          cal.add(Calendar.DAY_OF_YEAR, 7); 
        else if (currentScreen == ScreenType.MONTH)
          cal.add(Calendar.DAY_OF_YEAR, dayMonthNumb[cal.get(Calendar.MONTH)]);
        setDate(cal);
        jXMonthView.setSelectedDate(cal.getTime());
        jXMonthView.setFirstDisplayedDate(workSpace.getCurrentDay().getTimeInMillis());
      }
    }); 

    JPanel dsp = new JPanel();
    dsp.setBorder(new EmptyBorder(0,0,0,0));
    dsp.setOpaque(false);
    dsp.setLayout(new BoxLayout(dsp, BoxLayout.X_AXIS));
    dsp.setLayout(new GridLayout(1,5));
    dsp.setBorder(new javax.swing.border.EmptyBorder(2, 4, 6, 4));
    dsp.add(previousButton);
    dsp.add(dayButton);
    dsp.add(weekButton);
    dsp.add(monthButton);
    dsp.add(nextButton);
    mainTempToolBar.add(dsp);
    return retComp;
  }
    
     
    
  private JButton createToolbarButton(String text, String icon, int type) {
    JButton button = new CoolButton(type);
    try{
      button.setIcon(new ImageIcon(getClass().getResource("/resources/icons/" + icon + "_01.png")));
    }catch( Exception e) {}
    try{  
      button.setDisabledIcon(new ImageIcon(getClass().getResource("/resources/icons/" + icon + "_03.png")));
    }catch( Exception e) {}
    try{
      button.setRolloverIcon(new ImageIcon(getClass().getResource("/resources/icons/" + icon + "_02.png")));
    }catch( Exception e) {}                  
    button.setText(text);
    button.setBorder(BorderFactory.createEmptyBorder(4, 12, 3, 12));
    button.setFocusPainted(false);
    button.setHorizontalTextPosition(SwingConstants.CENTER);
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setRequestFocusEnabled(false);
    return button;
  }
    
    
  // Variables declaration - do not modify
  private JLabel LundiLabel;
  private JScrollPane agendaScrollPane;
  private JPanel bottomCenterPanel;
  private JPanel bottomLeftPanel;
  private JPanel bottomPanel;
  private JPanel bottomRightPanel;
  private JPanel centerPanel;
  
  private JPanel centerDayPanel;
  private JPanel centerWeekPanel;
  private JPanel centerMonthPanel;
  
  private JPanel dayNamePanel;
  private JPanel dayNameTopPanel;
  private JLabel dimancheLabel;
  private JPanel dimanchePanel;
  private JPanel headerCenterPanel;
  private JPanel headerLeftPanel;
  private JPanel headerPanel;
  private JPanel headerRightPanel;
  private JButton todayButton;
  private JButton jButton2;
  private JButton jButton3;
  private JButton jButton4;
  private JButton jButton5;
  private JButton jButton7;
  private JPanel jPanel11;
  private JScrollPane jScrollPane1;
  private JScrollPane jScrollPane2;
  private JScrollPane jScrollPane3;
  private JLabel jeudiLabel;
  private JPanel jeudiPanel;
  private JPanel leftPanel;
  private JPanel lundiPanel;
  private JLabel mardiLabel;
  private JPanel mardiPanel;
  private JLabel mercrediLabel;
  private JPanel mercrediPanel;
  private JXPanel rightPanel;
  private JLabel samediLabel;
  private JPanel samediPanel;
  private JPanel timeLeftPanel;
  private JLabel vendrediLabel;
  private JPanel vendrediPanel;
  private JPanel weekPanel;
  
  private JXMonthView jXMonthView;
  
  private JXCollapsiblePane rightCollapsiblePane;
  
  private JLabel yearLabel;  
  private JList calendarJList;
  private JLabel titleLabel;
  private JLabel calendarLabel;
  
  private JList echeancesJList;
  private JLabel echeancesLabel; 
  private CalendarCellRenderer bcr;
  
  private Component rightTopBox;   
  private AgendaNotePanel agendaNotePanel;
  private AgendaCalendrierPanel agendaCalendrierPanel;
  private boolean init= false;  
  
  static String dayTabName[] = {"Lun.","Mar.","Mer.","Jeu.","Ven.","Sam.","Dim."};
  static String dayMonthName[] = {"Jan.","Fev.","Mar.","Avr.","Mai.","Jui.","Jui.","Aou.","Sep","Oct","Nov","Dec"};
  static int dayMonthNumb[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  private Workspace workSpace;
}

